<?php

namespace App\Http\Controllers;

use App\Models\UserLogs;

use Illuminate\Foundation\Bus\DispatchesJobs;

use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct()
    {
        //用户浏览记录
//        $this->middleware(function ($request, $next) {
//            $user_id = auth()->guard('web')->id();
//            if(empty($user_id)) $user_id = 0;
//            //获取当前控制器
//            $action = \Route::current()->getActionName();
//            list($controller, $method) = explode('@', $action);
//            $controller = substr(strrchr($controller,'\\'),1);
//            $data = [
//              'user_id' => $user_id,
//              'controller' => $controller,
//              'route' => \Request::route()->getName(),
//              'link' => \Request::getUri(),
//            ];
//            if($controller !== 'PublicController'){
//                UserLogs::create($data);
//            }
//            return $next($request);
//        });

    }

    /**
     * writeJson 方法
     * @param int $statusCode 0成功 1失败
     * @param null $result 结果
     * @param null $msg 消息提示
     * @return bool
     */
    protected function writeJson($statusCode = 0,$result = null,$msg = null){
        $data = [
            "code"  => $statusCode,
            "data"  => $result,
            "msg"   => $msg ?? 'SUCCESS'
        ];
        return response()->json($data);
    }

}
